<!--
 * @Author: Zhouxin 2890091630@qq.com
 * @Date: 2024-08-27 00:02:37
 * @LastEditors: Zhouxin 2890091630@qq.com
 * @LastEditTime: 2024-08-27 00:15:27
 * @FilePath: \2024-8-22(26)-day13\this 3种情况指向.html
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>this 3种情况指向</title>
</head>
<body>
    <script>
        //函数内的this指向 调用函数方法的主体对象

        //对象.方法(); //方法内的this指向 .之前的对象

         //函数(); //this => window

         function f1(){
            console.log(this);
         }

         window.f1();//window调用的f1

         var x = 10;
         console.log(window.x);


         var obj = {
            name:"zzz",
            showName: function(){
                console.log(this.name);//zzzz
            }
         }
         obj.showName();//zzz this.name=>object.name

         //构造函数this指向实例化对象
    </script>
</body>
</html>